<template>
	<view>
		<view class="head">
			<view class="head_left" @tap="back()">
				<image src="../../../static/wode/return.png" mode=""></image>
				<text>返回</text>
			</view>
			<view class="head_mid">
				明细
			</view>
			<view class="head_right">

			</view>
		</view>
		<view class="marginLeft">
			<picker class="fontStyle" mode="date" fields="month" start="1971-01-01" :end="endDate" @change="starDateChange">
				<view class="uni-input" v-if="starDate==''">请选择<image class="down" src="../../../static/diqiuquan/down.png" mode=""></image>
				</view>
				<view class="uni-input" v-else>{{starDate}}
					<image class="down" src="../../../static/diqiuquan/down.png" mode=""></image>
				</view>

			</picker>
			<text style="padding-left: 10upx;">--</text>
			<picker class="fontStyle rightText" fields="month" mode="date" :start="starDate" :end="endDate" @change="closeDateChange">
				<view class="uni-input" v-if="closeDate==''">请选择<image class="down" src="../../../static/diqiuquan/down.png" mode=""></image>
				</view>
				<view class="uni-input" v-else>{{closeDate}}
					<image class="down" src="../../../static/diqiuquan/down.png" mode=""></image>
				</view>
				<!-- <image class="down" src="../../../static/diqiuquan/down.png" mode=""></image> -->
			</picker>
		</view>
		<!-- <text class="text1">增加500猫币 消耗2000猫币</text> -->
		<view class="body">
			<view class="body_item" @tap="toDetails(item.id,item.transaction_type)" v-for="(item,index) in payData" :key="index">
				<view class="item_left" v-if="item.type">
					<image v-if="item.logo_url" :src="item.logo_url" mode=""></image>
					<image v-else-if="item.map.userinfo.avatar" :src="item.map.userinfo.avatar" mode=""></image>
					<image v-else src="../../../static/logo2.png" mode=""></image>
					<view class="left_right">
						<text class="mingxi_type">{{item.content}}
							<text v-if="item.type=='gift'||item.type=='chat'">-{{item.map.userinfo.nick_name}}</text>
						</text>
						<text class="time">{{item.create_time}}</text>
					</view>
				</view>
				<view class="item_right1" v-if="item.transaction_type==true">
					+{{item.pay_count}}
				</view>
				<view class="item_right1" v-else>
					-{{item.pay_count}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				payData: [],
				type: '',
				endDate: '', //今天的日期
				starDate: '', //开始的日期
				closeDate: '', //结束的日期
				content: '',
				currentPage: 1,
				addMoney:'',
				reduceMoney:'',
			};
		},
		onLoad(option) {
			this.type = option.type
		},
		onShow() {
			this.getData()
			this.getEndDate()
		},
		onPullDownRefresh() {
			this.currentPage = 1;
			this.payData = [];
			this.getData();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.currentPage++;
			this.getData();
		},
		methods: {
			back() { //返回
				uni.navigateBack({
					delta: 1
				})
			},
			getEndDate() {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				// year = year + 2;
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				this.endDate = `${year}-${month}-${day}`;
			},
			starDateChange: function(e) {//选择开始时间
				this.starDate = e.target.value
				if (this.closeDate != '') {
					this.payData=[]
					this.getData()
				}
			},
			closeDateChange: function(e) {//选择结束时间
				this.closeDate = e.target.value
				if (this.starDate != '') {
					this.payData=[]
					this.getData()
				}
			},
			toDetails(id,type) {
				console.log(type)
				this.payData = []
				uni.navigateTo({
					url: '../moneyDetails/moneyDetails?id=' + id +'&transaction_type='+type
				})
			},
			getMonthDays(year,month){//根据年月获取天数
			  var stratDate = new Date(year,month-1,1),
			     endData = new Date(year,month,1);
			  var days = (endData -stratDate)/(1000*60*60*24);
			  return days;
			},
			getData() {
				var me = this;
				var data = {
					oper_id: uni.getStorageSync('user_id'),
					currentPage: this.currentPage
				}
				if (this.starDate != '' && this.closeDate != '') {
					data.start_time = this.starDate+'-01'
					var dayNum=this.getMonthDays(this.closeDate.split('-')[0],this.closeDate.split('-')[1])
					data.end_time = this.closeDate+'-'+dayNum
				}
				console.log(this.type)
				if (this.type == 'account') { //充值
					data.rcharge_type = 'account'
				} else {
					data.rcharge_type = 'member'
				}
				this.myAjaxNew({
					model: 'user',
					controllerName: 'userOrder',
					actionName: 'queryDetailListPage',
					data: data,
					successBack: function(res) {
						console.log(res, '明细')
						for (var i = 0; i < res.data.data.length; i++) {
							if (res.data.data[i].type == 'gift') {
								if (res.data.data[i].transaction_type == true) {
									res.data.data[i].content = '收到礼物'
								} else {
									res.data.data[i].content = '送礼物'
								}
							} else if (res.data.data[i].type == 'redenvelopes') {
								if (res.data.data[i].transaction_type == true) {
									res.data.data[i].content = '领红包'
								} else {
									res.data.data[i].content = '发红包'
								}
							} else if (res.data.data[i].type == 'sign') {
								res.data.data[i].content = '签到'
							} else if (res.data.data[i].type == 'recharge') {
								res.data.data[i].content = '充值'
							} else if (res.data.data[i].type == 'chat') {
								res.data.data[i].content = '聊天'
							} else if (res.data.data[i].type == 'task') {
								res.data.data[i].content = '任务'
							} else if (res.data.data[i].type == 'login') {
								res.data.data[i].content = '登录'
							}else if (res.data.data[i].type == 'video') {
								res.data.data[i].content = '视频聊天'
							}else if (res.data.data[i].type == 'class') {
								res.data.data[i].content = '上课'
							}else if (res.data.data[i].type == 'video_broadcast') {
								res.data.data[i].content = '视频观看'
							}else if (res.data.data[i].type == 'video_connection') {
								res.data.data[i].content = '视频连麦'
							}else if (res.data.data[i].type == 'live_broadcast') {
								res.data.data[i].content = '直播观看'
							}else if (res.data.data[i].type == 'live_connection') {
								res.data.data[i].content = '直播连麦'
							}
							me.payData.push(res.data.data[i])
						}
					},
				})
			}
		}
	}
</script>

<style scoped>
	.head {
		display: flex;
		justify-content: space-between;
		height: 128upx;
		background: #ffffff;
		padding: 0 24upx;
		position: fixed;
		width: 100%;
		top: 0;
	}

	.head image {
		width: 20upx;
		height: 36upx;
		margin-right: 9upx;
	}

	.head_left {
		display: flex;
		align-items: center;
		color: #666666;
		font-size: 32upx;
	}

	.head_mid {
		color: #333333;
		font-size: 36upx;
	}

	.head_right {
		width: 120upx;
	}

	.body {
		margin-top: 20upx;
		background: #FFFFFF;
	}

	.body_item {
		height: 130upx;
		padding: 0 24upx;
		border-bottom: 1upx solid #E6E6E6;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.item_left {
		display: flex;
		align-items: center;
	}

	.item_left image {
		width: 68upx;
		height: 68upx;
		margin-right: 30upx;
		border-radius: 50%;
		overflow: hidden;
	}

	.left_right {
		display: flex;
		flex-direction: column;
	}

	.mingxi_type {
		color: #333333;
		font-size: 28upx;
	}

	.time {
		color: #CCCCCC;
		font-size: 24upx;
	}



	.item_right1 {
		color: #46CECF;
		font-size: 36upx;
	}

	.item_right2 {
		color: #333333;
		font-size: 36upx;
	}

	.marginLeft {
		display: flex;
		padding: 24upx 24upx 0 24upx;
		align-items: center;
		font-size: 32upx;
		margin-top: 128upx;
	}

	.down {
		width: 24upx;
		height: 14upx;
	}

	.fontStyle {
		display: flex;
		align-items: center;
	}

	.text1 {
		color: #999999;
		font-size: 26upx;
		padding: 0 24upx;
	}
</style>
